import React,{ Component } from "react";
// 导入App组件
import NavBar from './navBar';
// 路由
import { Routes, Route,Navigate} from 'react-router-dom';
//引入页面，跳转路由
import Home from './content/home';
import Calculator from "./content/calculator";
import Login from "./content/login";
import Register from "./content/register";
import NotFound from "./content/notFound";


// 类组件方式创建
class App extends Component {
    state = { 
        is_login: true,
        username: "雯子",
    };

    render() {
        return (
            <React.Fragment>
                <NavBar is_login={this.state.is_login} username={this.state.username} />
                <div className='container'>
                    <Routes>
                        <Route path='/calculator' element={<Home />} />
                        <Route path='/calculator/home' element={<Home />} />
                        <Route path='/calculator/calculator' element={this.state.is_login ? <Calculator /> : <Navigate replace to="/calculator/login" />} />
                        <Route path='/calculator/login' element={this.state.is_login ? <Navigate replace to="/calculator" /> : <Login />} />
                        <Route path='/calculator/register' element={this.state.is_login ? <Navigate replace to="/calculator" /> : <Register />} />
                        <Route path='/calculator/404' element={<NotFound />} />
                        <Route path="/calculator/*" element={ <Navigate replace to="/calculator/404" /> } />
                    </Routes>
                </div>

            </React.Fragment>
        );
    }
}

// 导出
export default App;